clc;
clear all;
close all;

SNR_45 = 0.0:0.2:1.8;
SNR_90 = 0.0:0.2:1.2;
SNR_135 = 0.0:0.2:1.0;
SNR_180 = 0.0:0.2:1.0;

SNR_45x = 0.0:0.2:1.6;
SNR_90x = 0.0:0.2:1.0;
SNR_135x = 0.0:0.2:0.8;
SNR_180x = 0.0:0.2:0.8;

BER_2d3A_45 =  [0.01819444 0.00790795 0.00252390 0.00086290 0.00019439 0.00003697 0.00000707 0.00000238 0.00000114 0.00000075];
FER_2d3A_45 =  [0.38500000 0.18450185 0.06671114 0.02413710 0.00773694 0.00248973 0.00113685 0.00058301 0.00039598 0.00031554];
BER_2d3A_90 =  [0.01185938 0.00456918 0.00057903 0.00004952 0.00000469 0.00000155 0.00000069];
FER_2d3A_90 =  [0.27000000 0.11709602 0.01854943 0.00288351 0.00100045 0.00079148 0.00044860];
BER_2d3A_135 = [0.01012153 0.00183217 0.00014871 0.00000681 0.00000147 0.00000105];
FER_2d3A_135 = [0.28250000 0.06345178 0.00843526 0.00227967 0.00128695 0.00094544];
BER_2d3A_180 = [0.00706887 0.00070318 0.00005079 0.00000405 0.00000199 0.00000081];
FER_2d3A_180 = [0.24213075 0.04338395 0.00805088 0.00305885 0.00212780 0.00107411];

BER_2d3B_45 =  [0.02588194 0.01202778 0.00644044 0.00189132 0.00058543 0.00019125 0.00012235 0.00010098 0.00007882 0.00006841];
FER_2d3B_45 =  [0.57000000 0.31750000 0.20618557 0.10928962 0.06680027 0.04399472 0.03780718 0.03188776 0.03299241 0.02798769];
BER_2d3B_90 =  [0.02266319 0.00653420 0.00182768 0.00016667 0.00001948 0.00000475 0.00000310];
FER_2d3B_90 =  [0.50500000 0.17793594 0.05221932 0.00841822 0.00491183 0.00367863 0.00395054];
BER_2d3B_135 = [0.02152083 0.00506680 0.00060128 0.00002597 0.00000251 0.00000237];
FER_2d3B_135 = [0.48750000 0.13262599 0.02335903 0.00610314 0.00535877 0.00497216];
BER_2d3B_180 = [0.01671528 0.00275537 0.00016681 0.00000266 0.00000223 0.00000224];
FER_2d3B_180 = [0.42000000 0.08841733 0.01301236 0.00685166 0.00636335 0.00639059];


BER_2d3Am_45 =  [0.01793750 0.00820335 0.00292455 0.00067797 0.00014843 0.00002365 0.00000639 0.00000387 0.00000200 0.00000149];
FER_2d3Am_45 =  [0.37000000 0.17331023 0.07189073 0.02010454 0.00638774 0.00195286 0.00119454 0.00082014 0.00049398 0.00038521];
BER_2d3Am_90 =  [0.01198958 0.00365210 0.00062763 0.00005682 0.00000536 0.00000115 0.00000062];
FER_2d3Am_90 =  [0.28000000 0.09250694 0.01955417 0.00334102 0.00127668 0.00073989 0.00047747];
BER_2d3Am_135 = [0.00988300 0.00158377 0.00010390 0.00000549 0.00000164 0.00000109];
FER_2d3Am_135 = [0.24630542 0.04761905 0.00562461 0.00153170 0.00116167 0.00089224];
BER_2d3Am_180 = [0.00819068 0.00082795 0.00003388 0.00000168 0.00000056];
FER_2d3Am_180 = [0.22573363 0.02760144 0.00257646 0.00118569 0.00096774];

BER_2d3Bm_45 =  [0.02574653 0.01323958 0.00464720 0.00153911 0.00038848 0.00006035 0.00000755 0.00000168 0.00000046];
FER_2d3Bm_45 =  [0.51750000 0.26750000 0.11160714 0.03742515 0.01035947 0.00187038 0.00032968 0.00011377 0.00005277];
BER_2d3Bm_90 =  [0.02432118 0.00835322 0.00161123 0.00018240 0.00001164 0.00000067];
FER_2d3Bm_90 =  [0.51250000 0.20449898 0.04201681 0.00545375 0.00044257 0.00009626];
BER_2d3Bm_135 = [0.01994676 0.00467367 0.00048471 0.00002167 0.00000045];
FER_2d3Bm_135 = [0.49000000 0.11890606 0.01418842 0.00076827 0.00011499];
BER_2d3Bm_180 = [0.02039757 0.00269118 0.00020979 0.00000381 0.00000008];
FER_2d3Bm_180 = [0.48000000 0.07942812 0.00646412 0.00030527 0.00012335];

BER_9x27_40 =  [0.02011806 0.00911477 0.00427540 0.00122019 0.00021815 0.00005156 0.00001016 0.00000236 0.00000122 0.00000071];
FER_9x27_40 =  [0.44750000 0.21978022 0.10438413 0.03582945 0.00909504 0.00252729 0.00096530 0.00044703 0.00030338 0.00019797];
BER_9x27_80 =  [0.02000347 0.00527906 0.00097853 0.00015579 0.00000977 0.00000076];
FER_9x27_80 =  [0.48250000 0.15432099 0.03066544 0.00604339 0.00081950 0.00034862];
BER_9x27_120 = [0.01483796 0.00342269 0.00038736 0.00002003 0.00000059];
FER_9x27_120 = [0.37500000 0.10593220 0.01324503 0.00118424 0.00044807];
BER_9x27_160 = [0.01314149 0.00209417 0.00012502 0.00000324 0.00000029];
FER_9x27_160 = [0.36250000 0.06934813 0.00499376 0.00062261 0.00046443];



SNR_45_1d2 = -2.0:0.2:-0.2;
SNR_90_1d2 = -2.0:0.2:-0.4;
SNR_180_1d2 = -2.0:0.2:-1.0;

SNR_45x_1d2 = -2.0:0.2:-0.2;
SNR_90x_1d2 = -2.0:0.2:-0.4;
SNR_180x_1d2 = -2.0:0.2:-1.2;

BER_1d2_45 =  [0.03043519 0.01828241 0.00614392 0.00206756 0.00051708 0.00013754 0.00002652 0.00000725 0.00000463 0.00000425];
FER_1d2_45 =  [0.41500000 0.26750000 0.10183299 0.03529827 0.01180638 0.00493170 0.00297089 0.00180518 0.00156135 0.00166298];
BER_1d2_90 =  [0.02340509 0.00725249 0.00180075 0.00018222 0.00001330 0.00000232 0.00000149 0.00000114 0.00000070];
FER_1d2_90 =  [0.37500000 0.12970169 0.03607504 0.00559097 0.00187224 0.00116572 0.00082740 0.00068311 0.00042623];
BER_1d2_180 =  [0.01530903 0.00246108 0.00014201 0.00000552 0.00000127 0.00000093];
FER_1d2_180 =  [0.29000000 0.05382131 0.00539957 0.00143831 0.00143076 0.00098774];

BER_1d2M_45 =  [0.03372685 0.01480284 0.00660377 0.00187969 0.00051742 0.00011740 0.00001722 0.00000400 0.00000194 0.00000098];
FER_1d2M_45 =  [0.44750000 0.21551724 0.09930487 0.03341129 0.01123469 0.00301014 0.00100412 0.00053580 0.00040232 0.00025719];
BER_1d2M_90 =  [0.02518519 0.00706696 0.00171939 0.00019268 0.00001675 0.00000287 0.00000157 0.00000125 0.00000066];
FER_1d2M_90 =  [0.38750000 0.12722646 0.03594536 0.00562114 0.00168245 0.00110282 0.00085252 0.00071905 0.00040768];
BER_1d2M_180 =  [0.01850579 0.00283005 0.00011312 0.00000249 0.00000098];
FER_1d2M_180 =  [0.33750000 0.06203474 0.00466396 0.00154278 0.00124677];

SNR_45_1d3 = -5.0:0.2:-1.8;
SNR_90_1d3 = -5.0:0.2:-2.2;
SNR_180_1d3 = -5.0:0.2:-3.0;
SNR_45x_1d3 = -5.0:0.2:-1.4;
SNR_90x1_1d3 = -5.0:0.2:-2.4;
SNR_90x2_1d3 = -5.0:0.2:-2.8;
SNR_180x_1d3 = -5.0:0.2:-3.0;


%原始的1/3码字取自3GPP的提案
BER_1d3_45 =   [0.12700000 0.09442361 0.06375000 0.03806250 0.02309028 0.00781183 0.00359477 0.00113833 0.00039428 0.00011590 0.00009664 0.00005550 0.00002857 0.00002891 0.00001772 0.00001343 0.00000938];
FER_1d3_45 =   [0.90500000 0.73750000 0.59250000 0.40000000 0.25500000 0.12771392 0.09191176 0.04710316 0.02920561 0.01931621 0.01784121 0.01225791 0.00773395 0.00776820 0.00494389 0.00439599 0.00281334];
BER_1d3_90 =   [0.12430903 0.08543750 0.05243750 0.02032639 0.00689808 0.00151390 0.00026766 0.00006222 0.00002023 0.00001135 0.00000568 0.00000395 0.00000266 0.00000218 0.00000152];
FER_1d3_90 =   [0.92500000 0.80500000 0.60500000 0.30750000 0.15174507 0.03813883 0.01542972 0.00587924 0.00350165 0.00229505 0.00139573 0.00095546 0.00084489 0.00064332 0.00045829];
BER_1d3_180 =  [0.12215972 0.07455382 0.02919271 0.00991840 0.00140752 0.00009723 0.00001205 0.00000493 0.00000271 0.00000167 0.00000112];
FER_1d3_180 =  [0.98500000 0.87000000 0.56500000 0.26750000 0.06706908 0.01268231 0.00351346 0.00187126 0.00161387 0.00118335 0.00095178];

%基于3GPP的码字自己填充移位因子
BER_1d3M_45 =   [0.12632639 0.10026389 0.06072917 0.03871528 0.01650810 0.00875648 0.00303272 0.00099066 0.00027749 0.00010547 0.00004143 0.00001455 0.00000836 0.00000435 0.00000287 0.00000131 0.00000099];
FER_1d3M_45 =   [0.87750000 0.77750000 0.54500000 0.40250000 0.21141649 0.12285012 0.04780115 0.01864280 0.00808865 0.00435445 0.00233399 0.00126251 0.00077737 0.00057199 0.00038827 0.00020824 0.00015696];
BER_1d3M_90 =   [0.12005903 0.08726042 0.04618750 0.02114583 0.00556136 0.00181661 0.00038817 0.00004582 0.00001670 0.00000545 0.00000467 0.00000240 0.00000191 0.00000150 0.00000087];
FER_1d3M_90 =   [0.94000000 0.79250000 0.52500000 0.29500000 0.13927577 0.04301075 0.01597955 0.00527844 0.00253627 0.00138669 0.00124199 0.00081276 0.00071277 0.00053410 0.00034196];
BER_1d3M_180 =  [0.12090625 0.07676910 0.03394444 0.01006771 0.00104944 0.00009533 0.00001145 0.00000405 0.00000210 0.00000141 0.00000098];
FER_1d3M_180 =  [0.98000000 0.86500000 0.59500000 0.25250000 0.06218905 0.01122460 0.00329164 0.00184145 0.00133941 0.00101283 0.00079984];

%18X27基矩阵，最大列重9
BER_1d3C9_40 =   [0.15081250 0.12437500 0.09640278 0.07404861 0.04148611 0.02109665 0.01067796 0.00395551 0.00144713 0.00029598 0.00007651 0.00001052 0.00000624 0.00000383 0.00000322 0.00000263 0.00000166 0.00000119 0.00000098];
FER_1d3C9_40 =   [0.95500000 0.82750000 0.69750000 0.55250000 0.34750000 0.18587361 0.10060362 0.04282655 0.01530456 0.00470854 0.00219988 0.00120228 0.00088756 0.00058696 0.00054722 0.00045746 0.00031952 0.00023083 0.00019361];
BER_1d3C9_80 =   [0.15404167 0.13054167 0.09656597 0.05143403 0.02325092 0.00755291 0.00193873 0.00042135 0.00004374 0.00000610 0.00000204 0.00000129 0.00000116 0.00000094];
FER_1d3C9_80 =   [0.98000000 0.91750000 0.76250000 0.45750000 0.20746888 0.08658009 0.02260909 0.00630716 0.00157290 0.00098777 0.00082784 0.00049269 0.00047071 0.00039262];
BER_1d3C9_160 =  [0.15712674 0.13601736 0.09092708 0.04539236 0.01575746 0.00209376 0.00016761 0.00000176 0.00000065 0.00000051 0.00000048];
FER_1d3C9_160 =  [0.99250000 0.99250000 0.76500000 0.44250000 0.44250000 0.02589332 0.00286755 0.00104435 0.00066055 0.00058565 0.00052514];

%18X27基矩阵，最大列重12
BER_1d3C12_40 =   [0.14724306 0.12339583 0.09113889 0.06215278 0.03302778 0.01551270 0.00701672 0.00242391 0.00066700 0.00018009 0.00003888 0.00001238 0.00000420 0.00000244 0.00000207 0.00000114 0.00000087];
FER_1d3C12_40 =   [0.90750000 0.79500000 0.64500000 0.46750000 0.25250000 0.13531800 0.06269592 0.02517623 0.00954745 0.00312588 0.00123429 0.00084104 0.00053094 0.00032240 0.00032757 0.00018972 0.00017319];
BER_1d3C12_80 =   [0.15301736 0.11914583 0.07821875 0.04855903 0.01642502 0.00466699 0.00106119 0.00012319 0.00002006 0.00000485 0.00000188 0.00000071];
FER_1d3C12_80 =   [0.95000000 0.82500000 0.61750000 0.42000000 0.16260163 0.04803074 0.01191043 0.00231653 0.00089717 0.00066444 0.00046119 0.00046119];
BER_1d3C12_160 =  [0.15556597 0.12197569 0.07382118 0.02419792 0.00379783 0.00052128 0.00003040 0.00000138 0.00000122 0.00000069 0.00000055];
FER_1d3C12_160 =  [0.98250000 0.89500000 0.65500000 0.25500000 0.05711022 0.00883939 0.00238949 0.00085703 0.00100084 0.00065607 0.00000046];




figure(1);
semilogy(SNR_45, BER_2d3A_45, '-*k');
hold on;
semilogy(SNR_45, BER_2d3B_45, '-ok');
hold on;
semilogy(SNR_45, BER_2d3Am_45, '-sk');
hold on;
semilogy(SNR_45x, BER_2d3Bm_45, '->k');
hold on;
semilogy(SNR_45, BER_9x27_40, '-dk');
% hold on;
% semilogy(SNR_45, FER_2d3A_45, '--*k');
% hold on;
% semilogy(SNR_45, FER_2d3B_45, '--ok');
% hold on;
% semilogy(SNR_45, FER_2d3Am_45, '--sk');
% hold on;
% semilogy(SNR_45x, FER_2d3Bm_45, '-->k');
% hold on;
% semilogy(SNR_45, FER_9x27_40, '-dk');
grid on;
title('Comparison of (1080 720) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e A', 'BER for 16e B', 'BER for Design A', 'BER for Design B', 'BER for 9x27');

figure(2);
semilogy(SNR_90, BER_2d3A_90, '-*k');
hold on;
semilogy(SNR_90, BER_2d3B_90, '-ok');
hold on;
semilogy(SNR_90, BER_2d3Am_90, '-sk');
hold on;
semilogy(SNR_90x, BER_2d3Bm_90, '->k');
hold on;
semilogy(SNR_90x, BER_9x27_80, '-dk');
% hold on;
% semilogy(SNR_90, FER_2d3A_90, '--*k');
% hold on;
% semilogy(SNR_90, FER_2d3B_90, '--ok');
% hold on;
% semilogy(SNR_90, FER_2d3Am_90, '--sk');
% hold on;
% semilogy(SNR_90x, FER_2d3Bm_90, '-->k');
% hold on;
% semilogy(SNR_80x, BER_9x27_80, '-dk');
grid on;
title('Comparison of (2160 1440) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e A', 'BER for 16e B', 'BER for Design A', 'BER for Design B', 'BER for 9x27');

figure(3);
semilogy(SNR_180, BER_2d3A_180, '-*k');
hold on;
semilogy(SNR_180, BER_2d3B_180, '-ok');
hold on;
semilogy(SNR_180x, BER_2d3Am_180, '-sk');
hold on;
semilogy(SNR_180x, BER_2d3Bm_180, '->k');
hold on;
semilogy(SNR_180x, BER_9x27_160, '-dk');
% hold on;
% semilogy(SNR_180, FER_2d3A_180, '--*k');
% hold on;
% semilogy(SNR_180, FER_2d3B_180, '--ok');
% hold on;
% semilogy(SNR_180x, FER_2d3Am_180, '--sk');
% hold on;
% semilogy(SNR_180x, FER_2d3Bm_180, '-->k');
% hold on;
% semilogy(SNR_180x, BER_9x27_160, '-dk');
grid on;
title('Comparison of (4320 2880) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e A', 'BER for 16e B', 'BER for Design A', 'BER for Design B', 'BER for 9x27');


figure(4);
semilogy(SNR_45_1d2, BER_1d2_45, '-*k');
hold on;
semilogy(SNR_45_1d2, BER_1d2M_45, '-ok');
hold on;
% semilogy(SNR_45_1d2, FER_1d2_45, '-*k');
% hold on;
% semilogy(SNR_45_1d2, FER_1d2M_45, '-ok');
grid on;
title('Comparison of (1080 540) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e', 'BER for Design');

figure(5);
semilogy(SNR_90_1d2, BER_1d2_90, '-*k');
hold on;
semilogy(SNR_90_1d2, BER_1d2M_90, '-ok');
hold on;
% semilogy(SNR_90_1d2, FER_1d2_90, '-*k');
% hold on;
% semilogy(SNR_90_1d2, FER_1d2M_90, '-ok');
grid on;
title('Comparison of (2160 1080) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e', 'BER for Design');

figure(6);
semilogy(SNR_180_1d2, BER_1d2_180, '-*k');
hold on;
semilogy(SNR_180x_1d2, BER_1d2M_180, '-ok');
hold on;
% semilogy(SNR_180_1d2, FER_1d2_180, '-*k');
% hold on;
% semilogy(SNR_180x_1d2, FER_1d2M_180, '-ok');
grid on;
title('Comparison of (4320 2160) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 16e', 'BER for Design');


figure(7);
semilogy(SNR_45_1d3, BER_1d3_45, '-*k');
hold on;
semilogy(SNR_45_1d3, BER_1d3M_45, '-ok');
hold on;
semilogy(SNR_45x_1d3, BER_1d3C9_40, '-dk');
hold on;
semilogy(SNR_45_1d3, BER_1d3C12_40, '-sk');
% hold on;
% semilogy(SNR_45_1d3, FER_1d3_45, '-*k');
% hold on;
% semilogy(SNR_45_1d3, FER_1d3M_45, '-ok');
% hold on;
% semilogy(SNR_45x_1d3, FER_1d3C9_40, '-dk');
% hold on;
% semilogy(SNR_45_1d3, FER_1d3C12_40, '-sk');
grid on;
title('Comparison of (1080 360) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 3GPP', 'BER for Design', 'BER for 18X27 C9', 'BER for 18X27 C12');

figure(8);
semilogy(SNR_90_1d3, BER_1d3_90, '-*k');
hold on;
semilogy(SNR_90_1d3, BER_1d3M_90, '-ok');
hold on;
semilogy(SNR_90x1_1d3, BER_1d3C9_80, '-dk');
hold on;
semilogy(SNR_90x2_1d3, BER_1d3C12_80, '-sk');
% hold on;
% semilogy(SNR_90_1d3, FER_1d3_90, '-*k');
% hold on;
% semilogy(SNR_90_1d3, FER_1d3M_90, '-ok');
% hold on;
% semilogy(SNR_90x1_1d3, FER_1d3C9_80, '-dk');
% hold on;
% semilogy(SNR_90x2_1d3, FER_1d3C12_80, '-sk');
grid on;
title('Comparison of (2160 720) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 3GPP', 'BER for Design', 'BER for 18X27 C9', 'BER for 18X27 C12');

figure(9);
semilogy(SNR_180_1d3, BER_1d3_180, '-*k');
hold on;
semilogy(SNR_180_1d3, BER_1d3M_180, '-ok');
hold on;
semilogy(SNR_180_1d3, BER_1d3C9_160, '-dk');
hold on;
semilogy(SNR_180_1d3, BER_1d3C12_160, '-sk');
% hold on;
% semilogy(SNR_180_1d3, FER_1d3_180, '-*k');
% hold on;
% semilogy(SNR_180_1d3, FER_1d3M_180, '-ok');
% hold on;
% semilogy(SNR_180_1d3, FER_1d3C9_160, '-dk');
% hold on;
% semilogy(SNR_180_1d3, FER_1d3C12_160, '-sk');
grid on;
title('Comparison of (4320 1440) Codes');
xlabel('SNR(dB)');
ylabel('BER/FER');
legend('BER for 3GPP', 'BER for Design', 'BER for 18X27 C9', 'BER for 18X27 C12');



aa = 0;